/*
 * @Date: 2024-08-12 09:41:32
 * @LastEditors: 陈俊宇 467724386@qq.com
 * @LastEditTime: 2024-08-13 17:12:14
 */

import { defineStore } from 'pinia'
import { replyList, firstCategory } from '@/api'
export const useReplyStore = defineStore('reply', {
    state: () => {
        return {
            category: [],
            replyMap: {},
            replyPageMap: {},
        }
    },
    actions: {
        async fetchCategory() {
            const res = await firstCategory()
            this.category = res.data
        },
        async fetchReplyList({ msgId, id, query }) {
            const params = {
                page: this.replyPageMap[msgId],
                size: 5,
                queryData: {
                    categoryId: id,
                    query,
                },
            }
            const res = await replyList(params)

            if (res.data) {
                this.replyMap[msgId] = res.data
            } else {
                this.replyMap[msgId] = res.msg
            }

            if ((params.page + 1) * params.size > res.count) {
                this.replyPageMap[msgId] = -1
            }
        },
    },
    modules: {},
})
